﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;

public partial class admin_SelectSection : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SectionServices sectionServices = new SectionServices();
            List<Section> list = sectionServices.findAllSection();
            List<Section> baselist = new List<Section>();
            foreach (Section s in list)
            {
                if (s.BaseSection.SectionId == 0)
                {
                    baselist.Add(s);
                }
            }
            foreach (Section s in baselist)
            {
                TreeNode tn = new TreeNode(s.SectionName);
                tn.Value = s.SectionId.ToString();
                tn.ImageUrl = @"~/images/menu/system.gif";
                TreeView1.Nodes.Add(tn);
                AddTreeSonNode(s.SectionId, tn);
            }
        }
    }
    void AddTreeSonNode(int baseid, TreeNode treeNode)
    {
        List<Section> list = SectionServices.findByBaseSection(baseid);
        if (list.Count > 0)
        {
            foreach (Section s in list)
            {
                TreeNode tn = new TreeNode(s.SectionName);
                tn.Value = s.SectionId.ToString();
                tn.ImageUrl = @"~/images/menu/sale_manage.gif";
                treeNode.ChildNodes.Add(tn);
                AddTreeSonNode(s.SectionId, tn);
            }
        }
    }
    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
        
    }
}
